package com.yugao.fintech.antelope.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yugao.fintech.antelope.base.model.BasePlusPO;
import com.yugao.fintech.antelope.shop.assembly.TableCategoryAssembly;
import com.yugao.fintech.antelope.shop.mapper.TableCategoryMapper;
import com.yugao.fintech.antelope.shop.model.entity.ShopTableCategory;
import com.yugao.fintech.antelope.shop.model.rqrs.table.TableCategoryResp;
import com.yugao.fintech.antelope.shop.model.rqrs.table.TableCategorySaveReq;
import com.yugao.fintech.antelope.shop.model.rqrs.table.TableCategoryUpdateReq;
import com.yugao.fintech.antelope.shop.service.TableCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 桌台分类
 *

 */
@Slf4j
@Service
public class TableCategoryServiceImpl extends ServiceImpl<TableCategoryMapper, ShopTableCategory>
    implements IService<ShopTableCategory>, TableCategoryService {
    @Autowired
    private TableCategoryAssembly tableCategoryAssembly;
    @Override
    public List<TableCategoryResp> listCategory() {
    	return this.list(ShopTableCategory.lqw().orderByDesc(BasePlusPO::getCreatedAt)).stream()
    	        .map(tableCategoryAssembly::toTableCategoryResp).collect(Collectors.toList());
    }

    @Override
    public boolean saveCategory(TableCategorySaveReq req) {
        ShopTableCategory entity = tableCategoryAssembly.toTableCategory(req);
    	return this.save(entity);
    }

    @Override
    public boolean updateCategory(TableCategoryUpdateReq req) {
        ShopTableCategory entity = tableCategoryAssembly.toTableCategory(req);
    	return this.updateById(entity);
    }

    @Override
    public boolean deleteCategory(Long id) {
    	return this.removeById(id);
    }
    
    @Override
    public boolean batchDeleteCategory(List<Long> ids) {
    	return this.removeByIds(ids);
    }
}
